package com.itheima.springboot_08_ssmp3.dao;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.springboot_08_ssmp3.domain.Book;
import com.itheima.springboot_08_ssmp3.service.IBookService;
import com.itheima.springboot_08_ssmp3.service.impl.BookServiceImpl;
import com.itheima.springboot_08_ssmp3.service.impl.BookServiceImpl2;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
public class BookServiceTests2 {

    //private BookServiceImpl bookService;
    @Autowired
    private BookServiceImpl2 bookService;
    @Test
    void insertBookTest(){
        Book book = new Book();
        book.setName("基督山伯爵");
        book.setType("纸质版");
        book.setDescription("马克达蒙");
        bookService.save(book);
    }
    @Test
    void updateBookTest(){
        Book book = new Book();
        book.setId(13);
        book.setName("圣经");
        book.setType("纸质版");
        book.setDescription("上帝");

        bookService.updateById(book);
    }
    @Test
    void selectBookTest(){
        System.out.println(bookService.getById(14));
    }
    @Test
    void selectAllBookTest(){
        System.out.println(bookService.list());
    }
    @Test
    void deleteBookTest(){
        bookService.removeById(13);
    }
    @Test
    void pageBookTest(){
        IPage<Book> page=new Page<>(2,3);
        bookService.page(page);
        System.out.println(page.getCurrent());//当前页码
        System.out.println(page.getSize());//多少条
        System.out.println(page.getTotal());//供多少条
        System.out.println(page.getPages());//供多少页
        System.out.println(page.getRecords());//当前记录
    }
    //@Test
    //void queryBookTest(){//按条件查询
    //    QueryWrapper<Book> qw=new QueryWrapper<>();
    //    String name="经";
    //    qw.like(name !=null,"name",name);//先判断name是否为null,否则会报错
    //    bookDao.selectList(qw);
    //}
}
